{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d12ff15d",
   "metadata": {},
   "source": [
    "# 1.vowels.py\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "46fb9a46",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "### 需求：word中出现的vowels打印出来\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print (letter)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "b6b39697",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "e\n",
      "i\n",
      "o\n",
      "u\n"
     ]
    }
   ],
   "source": [
    "for word in vowels:   #循环遍历的第一个位置的元素请注意，名字不要与已经定义名字的变量重复\n",
    "    print (word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "0b77ac3a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "e\n",
      "i\n",
      "o\n",
      "u\n"
     ]
    }
   ],
   "source": [
    "for i in vowels:     # for的第二个元素，决定了我们循环的内容，循环的列表，每个元素单独在一行打印\n",
    "    print (i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "d8f59fc9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M\n",
      "i\n",
      "l\n",
      "l\n",
      "i\n",
      "w\n",
      "a\n",
      "y\n",
      "s\n"
     ]
    }
   ],
   "source": [
    "for letter in word:\n",
    "    print (letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "6457352a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print (letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c0e8311",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "9aa9ef8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['i', 'a']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# append()经常用于新建列表\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "found\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3bbad0f1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01ad331d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "908af7c1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "7bd0b905",
   "metadata": {},
   "source": [
    "# 练习\n",
    "# 购物车程序项目：\n",
    "\n",
    "　　要求：1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "\n",
    "　　   　　2、让用户输入商品编号进行商品的购买。\n",
    "\n",
    "　　  　　 3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "\n",
    "　　　　   4、用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "513e4d1f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入正确的支付宝余额：8888\n",
      "------- goods detail -------\n",
      "编号0，商品名称：课本,商品价格: 60 元\n",
      "编号1，商品名称：华为手机,商品价格: 8000 元\n",
      "编号2，商品名称：小米手机,商品价格: 199 元\n",
      "编号3，商品名称：奶茶,商品价格: 8 元\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 准备工作\n",
    "# 1.商品信息\n",
    "# goods_list = [\"课本-60\",\"华为手机-8000\",\"小米手机-199\",\"奶茶-8\"]\n",
    "goods_list = [\n",
    "    [\"课本\",60],\n",
    "              [\"华为手机\",8000],\n",
    "              [\"小米手机\",199],\n",
    "              [\"奶茶\",8]\n",
    "             ]\n",
    "\n",
    "# 2.用户购物信息\n",
    "user_shopping_list = []\n",
    "# 用户输入余额\n",
    "Alipay = input(\"输入正确的支付宝余额：\")\n",
    "info = '''------- goods detail -------\n",
    "编号0，商品名称：%s,商品价格: %s 元\n",
    "编号1，商品名称：%s,商品价格: %s 元\n",
    "编号2，商品名称：%s,商品价格: %s 元\n",
    "编号3，商品名称：%s,商品价格: %s 元\n",
    "\n",
    "'''%(goods_list[0][0],goods_list[0][1],\n",
    "     goods_list[1][0],goods_list[1][1],\n",
    "     goods_list[2][0],goods_list[2][1],\n",
    "     goods_list[3][0],goods_list[3][1],\n",
    "    )\n",
    "print(info)\n",
    "\n",
    "\n",
    "# 是不是应该循环了呢\n",
    "# 用户输入（余额）\n",
    "# 输入正确，打印商品列表\n",
    "\n",
    "## 用户输入商品编号\n",
    "## 1.输入的编号存在，判断余额是否够\n",
    "### 余额够，用户余额-商品价格\n",
    "### 余额不够，“你的余额不足”\n",
    "## 2.输入的编号不存在，“请输入正确的余额”\n",
    "# 输入错误，请输入正确的余额\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29f72495",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "for i in range(4):\n",
    "    print(\"------- goods detail -------\")\n",
    "    print(\"编号%s，商品名称：%s,商品价格: %s 元"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54efa591",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18b4ced7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "31f663fc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6477a18",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ecdbd10",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26898cdc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "7884bbd3",
   "metadata": {},
   "source": [
    "# 真"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "782a28d3",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-37-6605914397cb>, line 42)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-37-6605914397cb>\"\u001b[1;36m, line \u001b[1;32m42\u001b[0m\n\u001b[1;33m    else:\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 准备工作\n",
    "# 1.商品信息\n",
    "# goods_list = [\"\"]\n",
    "goods_list = [\n",
    "    [\"珍珠奶茶\",7],\n",
    "              [\"大杯珍珠奶茶\",8.5],\n",
    "              [\"加大杯珍珠奶茶\",9.5],\n",
    "              [\"桶装奶茶\",20]\n",
    "             ]\n",
    "user_shopping_car = [\n",
    "    \n",
    "]\n",
    "\n",
    "\n",
    "# 用户输入余额 输入input input的使用，结果是一个字符串\n",
    "Alipay = int(input(\"输入正确的支付宝余额：\"))\n",
    "\n",
    "# 循环遍历商品列表，将商品信息按照一定格式输出\n",
    "# 一定格式：商品编号 商品名称 商品价格\n",
    "while True :\n",
    "  \n",
    "    for i in range(len(goods_list)):    #  range会根据列表的长度变化而变化\n",
    "        print(\"商品编号 ：%s，商品名称 ：%s,商品价格: %s \"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "\n",
    "    # 让用户输入商品编号进行购买\n",
    "    # 用户输入的商品是否有 是否规范\n",
    "\n",
    "    # 思考：用户输入数值外，有没有可能输入不是数值 是文字\n",
    "    choice = input(\"请输入正确的商品编号：\")\n",
    "    if choice.isdigit():\n",
    "        choice = int(choice)\n",
    "    if choice > len(goods_list):\n",
    "    # 如果没有，返回没有\n",
    "      print (\"没有该商品\")\n",
    "    else:\n",
    "        # 如果有，判断金额够不够\n",
    "        if Alipay > goods_list[choice][1]:\n",
    "            # 余额够 加到购物车 扣余额\n",
    "            user_shopping_car.append(goods_list[choice])\n",
    "            Alipay = Alipay - goods_list[choice][1]\n",
    "            print (\"【%s】已加入购物车，您的【余额】还有： %s 元\"%(goods_list[choice][0],Alipay))\n",
    "            else:\n",
    "                print(\"您的余额不足\")\n",
    "                elif choice == \"q\":\n",
    "                    print(\"用户购物车： \",user_shopping_car)\n",
    "                    print\n",
    "                    break\n",
    "                    else:\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8b71f910",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1fa4a7cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ff03680",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70053f58",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15a943c3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f904758",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f242c62",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ddfe8e6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c76abf13",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
